X12 to FHIR System API - Implementation Template
Developer guide
FHIR to X12 Developer Guide
FHIR to X12 provides helper functions for mapping FHIR objects to X12 ones and reverse.
Module | Description |
---|---|
fhirtoAdditionalInfo275 | Module that provides support for submit 275 request mapping. |
fhirToSubmitRequest278 | Module that provides support for submit 278 request mapping. |
submitResponse278toFHIR | Module that provides support for submit 278 response mapping. |
claimInquiryResponse278toFHIR | Module that provides support for inquiry 278 response mapping. |
fhirTo278Inquiry | Module that provides support for inquiry 278 request mapping. |
fhirTo270Inquiry | Module that provides support for FHIR R4 CoverageEligibilityRequest to HIPAA X12 270 transformation. |
fhirTo837Claim | Module that provides support for claim 837 professional mapping. |
x12271ToFhirResponse | Module that provides support for HIPAA X12 271 to FHIR R4 Coverage Eligibility Response transformation. |
fhirConstants | This module implements FHIR constants that are used in CoverageEligibilityRequest and Response mapping. |
x12SegmentQualifiers | This module implements X12 segment qualifier functions. |
x12SegmentTools | This module implements X12 segment tools needed for 837, 270 and 271 segments. |
util | A library with needed DataWeave utility functions. |
fhirtoAdditionalInfo275
Module that provides support for submit 275 request mapping.
Source:
.src/main/resources/dwl/Submit/fhirtoAdditionalInfo275.dwl
fhirToSubmitRequest278
Module that provides support for submit 278 request mapping.
Source:
.src/main/resources/dwl/Submit/fhirToSubmitRequest278.dwl
submitResponse278toFHIR
Module that provides support for submit 278 response mapping.
Source:
.src/main/resources/dwl/Submit/submitResponse278toFHIR.dwl
claimInquiryResponse278toFHIR
Module that provides support for inquiry 278 response mapping.
Source:
.src/main/resources/dwl/Inquiry/claimInquiryResponse278toFHIR.dwl
fhirTo278Inquiry
Module that provides support for inquiry 278 request mapping.
Source:
.src/main/resources/dwl/Inquiry/fhirTo278Inquiry.dwl
fhirTo270Inquiry
Module that provides support for FHIR R4 CoverageEligibilityRequest to HIPAA X12 270 transformation.
Source:
.src/main/resources/dwl/fhirTo270Inquiry.dwl
fhirTo837Claim
Module that provides support for claim 837 professional mapping.
Source:
.src/main/resources/dwl/fhirTo837Claim.dwl
x12271ToFhirResponse
Module that provides support for HIPAA X12 271 to FHIR R4 Coverage Eligibility Response transformation.
Source:
.src/main/resources/dwl/x12271ToFhirResponse.dwl
fhirConstants
This module implements FHIR constants that are used in CoverageEligibilityRequest and Response mapping.
Source:
.src/main/resources/dwl/x12Util/fhirConstants.dwl
Functions
fun fhirConstants ()
Gets the constants used in lookup functions.
return A map of constants used.
x12SegmentQualifiers
This module implements X12 segment qualifier functions.
Source:
.src/main/resources/dwl/x12Util/x12SegmentQualifiers.dwl
Functions
fun getSegmentQualifiers ()
Gets the segment qualifiers for the 270, 278Submit, 278Inquiry, 275Submit and 837 transactions.
return A map of segment qualifiers.
x12SegmentTools
This module implements X12 segment tools needed for
837, 270 and 271 segments.
Source:
.src/main/resources/dwl/x12Util/x12SegmentTools.dwl
Functions
fun getResource (resourceBundle, resourceId, resourceType)
Function to get resource from bundle using either resourceId or resourceType.
param
resourceBundle
is the payload bundle to be filtered.
paramresourceId
is the ID of the resource to be used for filtering resources.
paramresourceType
is the type of resource to be used for filtering resources. Use either resourceId or resourceType for filtering.
fun createN3 (n3Type, n301, n302)
Creates an N3 address object with the provided arguments.
param
n3Type
is a string with the N3 type.
paramn301
is the first address line.
paramn302
is the second address line.
return A formatted N3 address object.
fun createN4 (n4Type, n401, n402, n403, n404, n407)
Creates an N4 address (city, state, zip) object with the provided arguments. Limitation: Doesn't support N407 - Assuming address is within United States of America, including its territories, or Canada
param
n4Type
is a string with the N$ type.
paramn401
is a string with the address city.
paramn402
is a string with the address state.
paramn403
is a string with the address postal code.
paramn404
is a string with the address country.
paramn407
is a string with the address district.
return A formatted N4 address object.
fun createDTP (dtpType, dtp01, dtp02, dtp03)
Creates a DTP (date time period) object with the provided arguments.
param
dtpType
is a string with DTP type.
paramdtp01
is a string with DTP qualifier.
paramdtp02
is a string with DTP format qualifier.
paramdtp03
is a string with DTP value.
return A formatted DTP object.
fun createREF (refType, ref01, ref02)
Creates an REF segment with the provided arguments.
param
refType
is a string with the provider code.
paramref01
is a string with the reference identification qualifier.
paramref02
is a reference with the ref02 element name being constructed with refType and REF02.
return X12 formatted REF segment.
fun getFHIRResource (inRequest, resourceId)
Function to lookup resource from bundle based on a resource's ID. Example: Pass in an Organization's ID and the response would be the Organization object from the bundle.
param
inRequest
- Input request to the API.
paramresourceId
- ID of resource to be looked up.
return Resource Object for the matching resource.
fun createPER (perType, per01, per02, per03, per04, per05, per06, per07, per08)
Creates a PER contact information object with the provided arguments.
param
perType
is a string with the PER type.
paramper01
is a string with the function code.
paramper02
is a string with the contact name.
paramper03
is a string with the number qualifier.
paramper04
is a string with the number value.
paramper05
is a string with the second number qualifier.
paramper06
is a string with the second number value.
paramper07
is a string with the third number qualifier.
paramper08
is a string with the third number value.
return A formatted PER contact information object.
fun createSV303 (inputData)
Creates a SV303 oral cavity designation object with the provided arguments.
param
inputData
is a claim resource object.
return A SV303 oral cavity object.
fun createSV3 (inputData)
Creates a SV3 dental service object with the provided arguments.
param
inputData
is a claim resource object.
return A formatted SV3 dental service object.
fun createSV1 (sv101_01, sv101_02, sv101_03, sv101_04, sv101_05, sv101_06, sv101_07, sv101_08, sv102, sv103, sv104)
Creates a SV1 professional service object with the provided arguments.
param
sv1_1
is a string with the EPSDT indicator.
paramsv1_2
is a string with product or service ID qualifier.
paramsv1_3
is a claim resource object.
return A formatted SV1 professional service object.
fun createSBR (perType, per01, per02, per03, per04, per05, per09)
Creates an SBR contact information object with the provided arguments.
param
perType
is a string with the PER type.
paramper01
is a string with the Contact Function code.
paramper02
is a string with the contact name.
paramper03
is a string with the Communication Number Qualifier.
paramper04
is a string with the Communication Number.
paramper05
is a string with the Communication Number Qualifier.
paramper09
is a string with the Contact Inquiry Reference.
return A formatted PER contact information object.
fun genderLookup (gndr)
Formats the provided gender string into a valid gender. String that can be cast to the gender value.
param
gndr
is the string with gender type.
return A required gender value.
fun createDMG (dmgType, dmg01, dmg02, dmg03)
Creates a DMG demographic information object with the provided arguments.
param
dmgType
is a string with the DMG type.
paramdmg01
is a string with the format qualifier.
paramdmg02
is a patient object.
return A formatted DMG demographic information object.
fun payerSequenceNumberPayerLookup (code)
Formats the provided gender string into a valid gender. String that can be cast to the gender value.
param
gndr
is the string with gender type.
return A required gender value.
fun relationCodeX12FHIR (inCode)
Function to convert X12 relationship code to FHIR format.
param
inCode
X12 relationship code.
return FHIR format relationship code.
fun genderLookupX12FHIR (inCode)
Function to convert X12 Gender codes to FHIR format.
param
inCode
X12 Gender code.
return FHIR format Gender code.
fun telecomTypeX12FHIR (inCode)
Function to convert X12 telecom codes to FHIR format.
param
inCode
X12 relationship code.
return FHIR format relationship code.
fun createTelecom (perSegment)
Function to create a telecom object for the FHIR resource using the X12 PER segment.
param
perSegment
PER segment from X12 message.
return telecom object formatted per FHIR specification.
fun pluckValuefromSeg (segment, selector)
Function to fetch element from segment with the key name prefix.
param
segment
from which to extract the element value.
fun createPWK (pwkType, pwk01, pwk02, pwk05, pwk06)
Function to create a PWK segment using the provided parameters.
param
pwkType
Describes the PWK segment being mapped.
parampwk01
Report Type code.
parampwk02
Report Transmission code.
parampwk05
Attachment control number.
parampwk06
Attachment description.
return X12 formatted BIN segment.
fun createMSG (msgType, msg01)
Function to create an MSG segment using the provided parameters.
param
msgType
Describes the MSG segment being mapped.
parammsg01
Message to be written to MSG segment.
return X12 formatted MSG segment.
fun benefitTypeLookup (x12BenefitType)
Function to translate X12 benefit type to FHIR format.
param
x12BenefitType
- X12 benefit type.
return FHIR benefit format benefit type.
fun createPRV (prvType, prv01, prv02, prv03)
Creates a PRV provider information object with the provided arguments.
param
prvType
describes the provider type being mapped. Not in use now, but could be used if multiple PRV segments with varying fields names are required.
paramprv01
is a string with the provider code.
paramprv02
is a string with the reference identification qualifier.
paramprv03
is a string with the provider taxonomy code.
return X12 formatted PRV segment.
fun termTypeLookup (x12TermCode)
Function to convert term type from X12 to FHIR.
param
x12TermCode
- X12 term type.
return FHIR format term type.
fun createResponseItem (item, fhirConstants)
Function to create item array within CoverageEligibilityResponse.
param
item
- item is the input x12's EB segment.
paramitemCategorySystem
- system identifier for item's category.
return - An array of item with benefit and other details.
fun fetchBenefitLoop (dependentPatientExists, benefitsLoop)
Function to fetch the benefits loop based on the patient being a subscriber or a dependent.
param
dependentPatientExists
- Boolean indicating if the patient is the subscriber or dependent.
parambenefitsLoop
- X12 271's 2100C or 2100D based on the patient being a dependent or subscriber.
fun createCoverageEligibilityResponse (fhirConstants, covRespId, bhtSegment, patientId, requesterType, requestorId, outcome, payorId, coverageId, benefitPeriod, benefitsLoop, dependentPatientExists)
Function to create CoverageEligibilityResponse.
param
fhirConstants
- List of constants used to for identifiers and system.
paramcovRespId
- Unique ID for CoverageEligibilityResponse.
parambhtSegment
- BHT segment from X12 271 input.
parampatientId
- the patient's ID (either subscriber or dependent) from X12 271 2100C Loop.
paramrequesterType
- Type of the party sending the CoverageEligibilityRequest can be either Practitioner or Organization.
paramrequestorId
- ID of the sender of the CoverageEligibilityRequest.
paramoutcome
- Outcome of the 271 X12 based on AAA segment.
parampayorId
- ID of the Information Source, which is the payer in this case.
paramcoverageId
- ID of the Coverage created as part of the bundle.
parambenefitPeriod
- Benefit begin and end date.
parambenefitsLoop
- 2110D or 2110C loop of the X12 271 based on the patient.
paramdependentPatientExists
- Boolean indicating if the patient is the subscriber or dependent.
fun RelationshipLookup (relateship)
Formats the provided coverage relationship string into a valid relationship string that can be cast to the relationship value. Limitation: Only support FHIR relations - Spouse, Child, and Other Relationship. Limitation: Only support FHIR relations - Spouse, Child, and Other Relationship.
param
relateship
is the string with gender type.
return A required gender value.
fun createINS (insType, ins01, ins02)
Function to create an INS segment with the provided input parameters.
param
insType
- INS segment for patient(subscriber or dependent).
paramins01
- insured indicator.
paramins02
- relationship to insured.
return An X12 formatted INS segment.
fun createINS (insType, ins01, ins02, ins08)
Creates an INS object with the provided arguments.
param
ins01
is an Insured Indicator value.
paraminso2
is value for Individual Relationship code.
paramins08
is a string with Employment Status code.
return X12 formatted INS segment.
fun insuredRelationLookup (relCode)
Formats the provided relationship code into a valid code that can be cast to relationship code.
param
relCode
is the code with relationship type.
return A required relationship code.
fun createBIN (bin01)
Creates a BIN object with the provided arguments.
param
bin01
is a Binary Data value.
return X12 formatted BIN segment.
fun createEFI (efi01)
Creates a EFI (Electronic Format Identification) object with the provided arguments.
param
efi01
is a Security Level code.
return X12 formatted EFI segment.
fun createCAT (cat01, cat02)
Creates a CAT (Category Of Patient Information Service) object with the provided arguments.
param
cat01
is a Attachment Report Type code.
paramcat02
is a Attachment Information Format code.
return X12 formatted CAT segment.
fun createLX (lx01)
Creates an LX object with the provided arguments.
param
lx01
is a Assigned Number.
return X12 formatted LX segment.
fun createNX1 (nx1_01)
Creates an NX1 object with the provided arguments.
param
nx1_01
is a Entity Identifier code.
return X12 formatted NX1 segment.
fun providerTypeLookup (inCode)
Function to convert provider type from FHIR to X12 format.
param
inCode
FHIR format lookup value.
return X12 format qualifier for provider.
fun lookupPERCommType (inCode)
Function to convert PER segments from FHIR format to X12 format.
param
inCode
- Telecom system in FHIR.
return X12 format communication type qualifier.
fun extensionLookUp (extension, valueType, url)
Function to lookup extension using URL comparison and return the appropriate code based on type of extension.
param
extension
- Array of extensions to be filtered.
paramvalueType
- Defines whether extension is of valueCodeableConcept or string.
paramurl
- URL of the extension being filtered identifying MilitaryStatus, leveOfService, and so forth.
fun fetchSupportingInfo (supportingInfoArray, eventCode, eventSystem)
Function to fetch claim resource's supporting Info for Patient Event, Admission, Discharge, AdditionalInfo, Message, and so forth.
param
supportingInfoArray
- List of supportinginfos from FHIR PAS Claim Resource.
parameventCode
- Codeable concept's code to filter the list.
parameventSystem
- Codeable concept's system to filter the list.
return - supportingInfo from FHIR Claim that matches the code and system.
fun formatPeriod (periodObject)
X12 formats the period range string with the provided FHIR period object.
param
periodObject
is an FHIR-formatted period object.
return A X12 period range string.
fun formatDateTime (str)
Formats the provided date string into a valid datetime string that can be cast to a date or a time.
param
str
is the current datetime string.
return A datetime formatted string.
fun createTRN (trnType, trn01, trn02, trn03, trn04)
Creates a TRN object with the provided arguments.
param
trnType
is a string with TRN type.
paramtrn01
is value for Trace Type code.
paramtrn02
is a string with TRN type Trace Number.
paramtrn03
is a string with Trace Assigning Entity Identifier.
paramtrn04
is a string with Trace Assigning Entity Additional Identifier.
return X12 formatted TRN segment
fun createHI (hi101, hi102, hi201, hi202)
Function to create HI segment with provided input parameters.
param
hi101
- Diagnosis code classification library identifier.
paramhi102
- Diagnosis code.
paramhi201
- Diagnosis code classification library identifier.
paramhi202
- Diagnosis code.
return An X12 formatted HI segment.
fun createHI (hi01, hi02)
Creates an HI healthcare information object with the provided arguments.
param
hi01
is a segment qualifier for diagnosys code admitting.
paramhi02
is a segment qualifier for diagnosys code principal.
paramhi03
is a segment qualifier for diagnosys code patientreasonforvisit.
paramhi04
is a string with diagnosys code.
fun createUM (um01, um02, um03, um0401, um0402, um0501, um0504, um06)
Creates a UM object with the provided arguments.
param
um01
is request category code.
paramum02
is certification type code.
paramum03
is service type code.
paramum0401
is a sub element of UM04 for facility code.
paramum0402
is a sub element of UM04 for facility code qualifier.
paramum0501
is a sub element of UM05 for related causes code.
paramum0504
is a sub element of UM05 for state or province code.
paramum0506
is the level of service code.
return X12 formatted UM segment.
fun createSubmit2000ELoop (inRequest, claimResource, segmentQualifiers, fhirConstantsObj, patientDates, claimSupportingInfo)
Function creates 2000E_Loop and its child loops like 2010EA and 2000F; 2000E_Loop includes TRN, UM, DTP,HI,PWK,MSG, 2010EA_Loop and 2000F_Loop; 2010EA_Loop includes NM1, N3, N4, PER, PRV; 2000F_Loop includes TRN, REF, UM, DTP, SV1 or SV2. This loop can occur in either 2000C at the subscriber level, when the subscriber is the patient; or it can occur at 2000D at the beneficiary level, when a dependent of the subscriber is the patient.
fun getEventLoop (loop2000E, loop2000FExists)
Function to get EventLoop from 2000E or 2000F. There are situations where 2000F loops are not populated in the X12 message. This function looks at both and returns the one that is present.
param
loop2000E
is the 2000ELoop from X12 Response.
_paramloop2000FExists
is a boolean that identifies the presence of a 2000FLoop.
_return Loop structure of either 2000E or 2000F.
fun getExtensionValue (LoopESegName, LoopFSegName, LoopE_Element, LoopF_Element, loop2000FExists, loop2000E)
Function to get extension values segment from either 2000E or 2000F loops. There are situations where 2000F loops are not populated in the X12 message with parameters LoopESegName,LoopFSegName,LoopE_Element,LoopF_Element,loop2000FExists,loop2000E. This function looks at both and returns the element from 2000F_Loop if it exists, else from 2000E_Loop. This function looks at both and returns the element from 2000F_Loop if it exists else from 2000E_Loop.
param
LoopESegName
is the segment name from 2000ELoop of X12 Response.
_paramLoopFSegName
is the segment name from 2000ELoop of X12 Response.
_paramLoopE_Element
is the element name from 2000ELoop of X12 Response.
_paramLoopF_Element
is the element name from 2000ELoop of X12 Response.
_paramloop2000FExists
is a boolean that identifies the presence of a 2000FLoop.
_paramloop2000E
is the 2000ELoop from X12 Response.
_return Loop structure of either 2000E or 2000F.
fun createInquiry2000ELoop (inRequest, claimResource, segmentQualifiers, fhirConstantsObj, patientDates, claimSupportingInfo)
Function creates 2000E_Loop and its child loops like 2010EA and 2000F; 2000E_Loop includes TRN, DTP, 2010EA_Loop and 2000F_Loop; 2010EA_Loop includes NM1, N3, N4, PER, PRV; 2000F_Loop includes TRN, UM, HCR, REF, DTP, SV1 or SV2. This loop can occur in either 2000C at the subscriber level, when the subscriber is the patient, or it can occur at 2000D at the beneficiary level, when a dependent of the subscriber is the patient.
fun createHCR (hcr01)
Creates a HCR segment with provided arguments.
param
hcr01
is a string with the action code for HCR.
return X12 formatted HCR segment.
util
A library with needed DataWeave utility functions.
Source:
.src/main/resources/dwl/util.dwl
Functions
fun mapGuid (InStr: String)
Generates a GUID with the provided string. This is helpful because the GUID generated is predictable.
param
InStr
is the input string to the hash function.
return A string with the predictable hashed value.
fun toString (data)
Converts anything to a JSON string representation. Note that if you are serializing an object datetime fields may have local timezone information so this can cause issues with repeatability for munit tests. Note that the writeAttributes part is very important so that the XML attributes will be converted to string as well.
param
data
is the data type to convert to JSON.
return A JSON formatted string of the provided variable.
fun clean (obj: Object)
Cleans the provided object of blank strings, null values, empty objects, and empty arrays.
param
obj
is an Object to clean.
return A cleaned object.
fun clean (arr: Array)
Cleans the provided array of blank strings, null values, empty objects, and empty arrays.
param
arr
is an Array to clean.
return A cleaned Array.
fun removeNull (arr: Array)
Removes all null items from an array.
param
arr
is an array.
return An array with null items removed.
fun removeNull (obj: Object)
Removes all null values from an object.
param
obj
is an object.
return An object with null values removed.
fun formatDate (dateStr)
Formats the provided X12 date (YYYYMMDD) to the FHIR date format (YYYY-MM-DD). If the provided date doesn't match the X12 format, it simply returns what was provided.
param
dateStr
is a string with the X12 date to format.
return A FHIR formatted date or what was passed in if the X12 format isn't matched.
fun removeGeneratedIds (data)
Removed any generated IDs such as GUIDS from the payload for testing purposes.
param
data
is FHIR bundle with the data to remove IDs from.
return The FHIR bundle with generated IDs removed.
fun removeAllInstances (data, fieldNames: Array)
Recursivly removes all instances of the provided fieldName within the provided data structure.
param
data
is an array or object to remove the field from.
paramfieldNames
is a array of strings with the field names to remove.
return The data with the field removed.
fun getSetHeader (data)
Gets the first Set Header (ST) line in the message and returns it.
param
data
is a X12 payload.
return A string with the Set Header line or null.
fun getXTransactionSetValue (data)
Gets the x-transaction-set header value to provide to X12 system API from the provided message.
param
data
is a X12 payload.
return The x-transaction-set header value for the provided message or an empty string if not matched.